package connector

import (
    "crypto/rand"
    "crypto/rsa"
    "crypto/x509"
    "encoding/pem"
)

func GenHostKey() ([]byte, error) {
    key, err := rsa.GenerateKey(rand.Reader, 2048)
    if err != nil {
        return nil, err
    }
    if err := key.Validate(); err != nil {
        return nil, err
    }
    blk := pem.Block{
        Type:       "RSA PRIVATE KEY",
        Bytes:      x509.MarshalPKCS1PrivateKey(key),
    }
    return pem.EncodeToMemory(&blk), nil
}